﻿//----------------------------------------------------------------------------------------------------
// The Node lsit displays a vertical list of node types.
//----------------------------------------------------------------------------------------------------

package HG.Visual
{
	import flash.display.*;
	import flash.events.*;
	
	import HG.GameService;
	
	import HG.Managers.InventoryManager;
	import HG.Managers.PlayerManager;
	
	import HG.Events.InventoryEvent;
	
	import HG.Debug;
	import HG.GameDataTypes.Item;
	
	public class VisualInventory extends MovieClip
	{
		//----------------------------------------------------------------------------------------------------
		public function VisualInventory() 
		{
			stop();
			loaderInfo.addEventListener(Event.INIT, onInit);
		}
  
  		//----------------------------------------------------------------------------------------------------
		public function onInit(e:Event)
		{
			
			var inventoryManager:InventoryManager = GameService.GetInstance().GetInventoryManager();
			
			inventoryManager.addEventListener(InventoryEvent.NEW, OnItemNew);
			inventoryManager.addEventListener(InventoryEvent.USED, OnItemUsed);
		}
		
		//----------------------------------------------------------------------------------------------------
		protected function OnItemNew(evt:InventoryEvent)
		{
			var playerID:Number = GameService.GetInstance().GetPlayerManager().GetCurrentPlayerID();
			
			if (evt.m_playerID != playerID)
				return;
				
			var visItem:VisualItem = new VisualItem();
			addChild(visItem);
			
			
			var inventoryManager:InventoryManager = GameService.GetInstance().GetInventoryManager();
			var item:Item = inventoryManager.GetItem(evt.m_itemID);
			
			// Encryption Key
			visItem.Encryption.visible = true;
			var encryptionKey:Number = Number(item.GetContents());
			visItem.Encryption.SetValue(encryptionKey);
		}
		
		//----------------------------------------------------------------------------------------------------
		protected function OnItemUsed(evt:InventoryEvent)
		{
			var playerID:Number = GameService.GetInstance().GetPlayerManager().GetCurrentPlayerID();
			
			if (evt.m_playerID != playerID)
				return;
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}









